<!-- * WanlShop - App全局模板配置
 * @author 深圳前海万联科技有限公司 <wanlshop@i36k.com> 
 * @link http://www.wanlshop.com
 * 
 * @本程序受法律保护，著作权©软著登记号2020SR0255711 < 未经版权所有权人书面许可，不能用于商业用途！>
 * 1
 * @获取许可
 * 后台下载：https://www.fastadmin.net/store/wanlshop.html
 * 帮助文档：https://doc.fastadmin.net/wanlshop
 * 
 * @stress 本程序仅用作FastAdmin付费插件（WanlShop B2B2C商城）API使用，未经版权所有权人书面许可，不能自行用于商业用途
 * @creationtime  2019年9月10日12:52:20
 * @lasttime 2020年6月9日09:26:07
 * @version 1.0.0
 -->
<script>
	import util from '@/utils/util.js'
	import {
		HTTP_REQUEST_URL,
		WX_MAP_KEY
	} from './config.js';
	
	var QQMapWX = require('@/utils/qqmap-wx-jssdk.min.js')
	var qqmapsdk = new QQMapWX({
		key: WX_MAP_KEY
	});
	export default {
		globalData: {
		
			ip: HTTP_REQUEST_URL,
			logo_url : require('@/static/image/logo.png'),
			ad_info: {},
			navHeight: 0,
			windowHeight: 0,
			routineStyle: '#ffffff',
			themeColor: '#0A6FFF',
			openPages: '',
			spid: 0,
			code: 0,
			urlImg: "",
			url : HTTP_REQUEST_URL,
			token: '',
			isLog: false,
			seconds: 0,
			userInfo: {},
			loginType: 'routine',
			tntInstId: "",
			scene: "",
		
			appid: '', // wx705e2a398c76e600 公众号  | 2021002141612683 支付宝 2021002163691727 支付宝 2021004158619519 支付宝
		},
		
		onShow(options) {
			// 获取支付宝启动参数
			uni.setStorageSync('onShow_app', options);
			uni.setStorageSync('app_key', '')
		},
		toJSON() {},
		onLaunch: function(options) {
			// 获取支付宝启动参数
			uni.setStorageSync('onLaunch_app', options)
			
			if (this.$route) {
				let sId = this.$route.query ? this.$route.query.sId : '';
				if (sId) {
					uni.setStorageSync("sId", sId)
				}
	
			}
	
	
			let that = this;
			// 获取导航高度；
			uni.getSystemInfo({
				success: res => {
					//导航高度
					this.globalData.navHeight = res.statusBarHeight * (750 / res.windowWidth) + 97;
					this.globalData.windowHeight = res.windowHeight;
				},
				fail(err) {}
			});
	
			// 获取定位 
			// qqmapsdk.reverseGeocoder({
			// 	success: result => {
			// 		if (result.status == 0) {
			// 			this.globalData.ad_info = result.result.ad_info
			// 		}
			// 	}
			// })
	
	
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate()
	
			updateManager.onUpdateReady(function() {
				uni.showModal({
					title: '更新提示',
					content: '新版本已经准备好，是否重启应用？',
					success: function(res) {
						if (res.confirm) {
							updateManager.applyUpdate()
						}
					}
				})
			});
			updateManager.onUpdateFailed(function() {
				return that.Tips({
					title: '新版本下载失败'
				});
			})
			
			// #ifdef MP-XHS
			const accountInfo = xhs.getAccountInfoSync();
			console.log(accountInfo.miniProgram.appId) // 小程序 appId
			this.globalData.appid = accountInfo.miniProgram.appId
			
			// #endif
	
			// #ifdef H5
			this.globalData.appid = 'wx705e2a398c76e600'
			// #endif
			// // #ifndef H5
			// this.globalData.appid = ''
			// // #endif
			// #ifdef MP-ALIPAY
			this.globalData.appid = my.getAppIdSync().appId;
			// #ifdef MP-XHS
			alert(1)
			const accountInfo = xhs.getAccountInfoSync();
			console.log(accountInfo.miniProgram.appId) // 小程序 appId
			this.globalData.appid = accountInfo.miniProgram.appId
			// #endif
	
			// this.globalData.appid = '2021002141612683''
			// this.globalData.appid = '2021004158619519'
			switch (this.globalData.appid) {
				case "2021004158619519":
					this.globalData.tntInstId = "vG2_nJei"
					this.globalData.tntInstId = "SCE01330339"
					break;
				default:
					break;
			}
			if(options.path != 'pages/index/index')
			{
				return
			}
			
			let url = ""
			if (this.globalData.appid == "2021004169628260") {
				url = "/pages/visa/detail"
				
			}
			else if (this.globalData.appid == "2021005129638440" || this.globalData.appid == "2021004168681484") {
				//新加坡
				url = "/pages/visa/detail?id=a490f713da3d4a11b42f969a38964c18"
			}
			else if (this.globalData.appid == "2021004171611561" ) {
				
				url = "/pages/visa/detail?__id__=1&id=5200458ffea24f59b78b3fa249739e95"
			}
			
			else {
				url = "/pages/index/index"
			}
			uni.reLaunch({
				url : url,
				success() {}
			});
			
			
			
	
			// #endif
		},
		
		methods: {
	
			/*
			 * 信息提示 + 跳转
			 * @param object opt {title:'提示语',icon:''} | url
			 * @param object to_url 跳转url 有5种跳转方式 {tab:1-5,url=跳转地址}
			 */
			Tips: function(opt, to_url) {
				return util.Tips(opt, to_url);
			},
	
			/*
			 * 合并数组
			 * @param array list 请求返回数据
			 * @param array sp 原始数组
			 * @return array
			 */
			SplitArray: function(list, sp) {
				return util.SplitArray(list, sp)
			},
			// 跳转
			goToPage(to_url) {
				uni.navigateTo({
				url : to_url,
					fail: () => {
						uni.switchTab({
							url : to_url
						});
					}
			});
	},
	showToast(msg) {
			uni.showToast({
				icon: 'none',
				title: msg
			})
		},
		queryNodes(id, attr) {
			return new Promise((resolve, reject) => {
				let query = uni.createSelectorQuery()
				query.select(id).boundingClientRect()
				query.exec((res) => {
					resolve(res[0][attr])
				})
			})
		},
	
	}
	}
</script>

<style>
	/* #ifndef APP-NVUE */
	/* @import 'static/style/colorui.css'; */
	/* @import 'static/style/wanlshop.css';
	@import 'static/style/iconfont.css';
	@import "static/style/icon.css"; */
	/* #endif */
</style>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	body, uni-app {
		background-color: #f5f6f8;
	}
</style>

